* Begin log file
capture log close sublog
log using "$projdir/log/1_google_build.txt", name(sublog) text replace

*-------------------------------------------------------------------------------
* Description: Clean Google mobility data
* Author: Carl McPherson
*
* Updated: June 30, 2023
*-------------------------------------------------------------------------------

* Import google data from recovery tracker (ie Chetty et al 2021) 
use "$projdir/dta/build/src/gm_county", replace 

gen date = mdy(month, day, year)
format %td date
 
* Keep only relevant dates 
keep if inrange(date, 21989, 22111)

foreach v in gps_retail_and_recreation gps_workplaces {
		gen nm_`v' =! mi(`v')
}

sort county date 
order county date

collapse (sum) gps* nm_*, by(countyfips)
rename nm_gps_* nm_*

gen workplace = gps_workplace / nm_workplace
gen retail = gps_retail / nm_retail

* Save
save "$projdir/dta/build/cln/covid_index", replace

* Close log file
log close sublog
